﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.Slaughter
{
    public class SlaughterCreateImagesHandler : IRequestHandler<SlaughterCreateImagesCommond, Rulst>
    {
        private readonly IbaseRpository<ProductionPutImages> _ProductionPutImages;

        public SlaughterCreateImagesHandler(IbaseRpository<ProductionPutImages> productionPutImages)
        {
            _ProductionPutImages = productionPutImages;
        }

        public async Task<Rulst> Handle(SlaughterCreateImagesCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };


            var lists = _ProductionPutImages.Query().Where(x => x.ProDuctionBasicid == request.ProDuctionBasicid && x.Stypeid == Typenum.相关资质).ToList();

            if(lists.Count<6)
            {
                var list = new ProductionPutImages()
                {

                    Stypeid = Typenum.相关资质,
                    ProDuctionBasicid = request.ProDuctionBasicid,
                    PutImages = request.iamges,
                    Putid = 0,
                };


                query.data = _ProductionPutImages.Add(list);
            }
            else
            {

                query.Code = -7;
               
            }

            


            return query;

            
        }
    }
}
